﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Net;
using System.IO;

namespace RRTWSTestDSD.UtilTests
{
    [TestClass]
    public class UnitTest1
    {
        [TestMethod]
        public void TestMethod1()
        {
            //string postdata = "{\"body\":\"DemoPruebaMnesaje\"}";
            string postdata = "body=DemoPruebaMnesaje";
            byte[] data = Encoding.UTF8.GetBytes(postdata);
            HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://localhost:8161/api/message/TEST?type=queue");
            req.Method = "POST";
            req.ContentLength = data.Length;
         //   req.ContentType = "application/json";
            req.ContentType = "application/x-www-form-urlencoded";
            String username = "admin";
            String password = "admin";
            String encoded = System.Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(username + ":" + password));
            req.Headers.Add("Authorization", "Basic " + encoded);
            var reqStream = req.GetRequestStream();
            reqStream.Write(data, 0, data.Length);
            HttpWebResponse res = null;

                res = (HttpWebResponse)req.GetResponse();
                StreamReader reader = new StreamReader(res.GetResponseStream());
                string asientoJson = reader.ReadToEnd();

                Console.WriteLine(asientoJson);
                Console.ReadLine();

                Assert.AreEqual("Message sent", asientoJson);

        }
    }
}
